package com.dha.caodangcongnghe;

import com.dha.asynctask.DangThongBaoAsyncTask;
import com.dha.status.NetworkStatus;
import com.dha.ultility.QuangCao;
import com.dha.variable.ThongTinTaiKhoan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class DangThongBao extends ActionBarActivity implements OnClickListener {
	private Button btNhapLai, btGoiThongBao;
	private EditText etTieuDe, etNoiDung;
	private TextView txGoiY;
	private NetworkStatus networkStatus;
	
//	private QuangCao quangCao;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_dang_thongbao);
		
//		quangCao = new QuangCao(this, DangThongBao.this);
		
		btNhapLai = (Button) findViewById(R.id.bt_goiThongBao_NhapLai);
		btGoiThongBao = (Button) findViewById(R.id.bt_goiThongBao_GoiThongBao);

		etNoiDung = (EditText) findViewById(R.id.etNoiDungThongBao);
		etTieuDe = (EditText) findViewById(R.id.etTieuDeThongBao);

		txGoiY = (TextView) findViewById(R.id.tv_goiThongBao_TenNguoiGoiThongBao);

		txGoiY.setText("Thông báo sẽ được đăng với tên "
				+ ThongTinTaiKhoan.hoTen);

		btGoiThongBao.setOnClickListener(this);
		btNhapLai.setOnClickListener(this);

		etTieuDe.requestFocus();

		networkStatus = new NetworkStatus(getBaseContext());
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bt_goiThongBao_NhapLai:
			etTieuDe.setText(null);
			etNoiDung.setText(null);
			etTieuDe.requestFocus();
			break;
		case R.id.bt_goiThongBao_GoiThongBao:
			if (networkStatus.isConnected()) {
				DangThongBaoAsyncTask asyncTask = new DangThongBaoAsyncTask(
						DangThongBao.this, ThongTinTaiKhoan.maTaiKhoan,
						etTieuDe.getText().toString(), etNoiDung.getText()
								.toString());
				asyncTask.execute();
			} else {
				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
				startActivity(intentLoi);
			}
			break;
		}

	}

}
